<%@ page import="java.util.List" %>
<%@ page import="com.letv.whatslive.model.mysql.system.SysFunction" %>
<%@ page import="com.google.common.collect.Lists" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page contentType="text/html;charset=utf-8" language="java" %>
<!-- BEGIN SIDEBAR LEFT -->
<div class="sidebar-left sidebar-nicescroller">
    <ul class="sidebar-menu">
        <%
            String FUNC_KEY_LEFTPAGE = "fId";
            int fIdLeftPage = 0;
            String fIdStringLeftPage = request.getParameter(FUNC_KEY_LEFTPAGE);
            if(StringUtils.isNumeric(fIdStringLeftPage)){
                fIdLeftPage = Integer.valueOf(fIdStringLeftPage);
            }
            List<SysFunction> f1ListLeftPage = null;
            //根据fId获取topFunc
            SysFunction topFuncLeftPage = null;
            if(fIdLeftPage > 0){
                topFuncLeftPage = WebUtils.getTopFunctionBySubFuncId_Cache(request, fIdLeftPage);
                f1ListLeftPage = WebUtils.getFunctionListByLoginUserAndParentFuncId_Cache(request, topFuncLeftPage.getId());
            }else {
                List<SysFunction> topFuncListLeftPage = WebUtils.getTopFunctionListByLoginUser_Cache(request);
                if(topFuncListLeftPage != null && topFuncListLeftPage.size() > 0){
                    topFuncLeftPage = topFuncListLeftPage.get(0);
                    SysFunction firstLeafFunc = WebUtils.getFirstLeafFunctionByLoginUserAndTopFunction_Cache(request, topFuncLeftPage.getId());
                    if(firstLeafFunc != null){
                        fIdLeftPage = firstLeafFunc.getId();
                    }
                    f1ListLeftPage = WebUtils.getFunctionListByLoginUserAndParentFuncId_Cache(request, topFuncLeftPage.getId());
                }else{
                    f1ListLeftPage = Lists.newArrayList();
                }
            }
            for(int i = 0; i < f1ListLeftPage.size(); i++) {
                SysFunction f1 = f1ListLeftPage.get(i);
                String folderClass = "";
                String folderIcon = "";
                if(null!=f1.getIconUrl()){
                    folderIcon = f1.getIconUrl();
                }
                String folderSelected = "";
                boolean isActiveF1 = WebUtils.isFuncActive_Cache(request, f1, fIdLeftPage);

                if (isActiveF1) {
                    GLOBAL_FOLDER_NAME = f1.getFuncName();
                    folderClass = "active selected";
                    folderSelected = "visible";
                }

        %>
        <li class="<%=folderClass%>">
            <a href="#fakelink">
                <i class="fa <%=folderIcon%> icon-sidebar"></i>
                <i class="fa fa-angle-right chevron-icon-sidebar"></i>
                <%=f1.getFuncName()%>
            </a>
            <ul class="submenu <%=folderSelected%>">
                <%
                    if(f1.getIsLeaf() == null || f1.getIsLeaf() != 1){
                        if(f1.getIsLeaf() == null || f1.getIsLeaf() != 1){
                            List<SysFunction> f2List = WebUtils.getFunctionListByLoginUserAndParentFuncId_Cache(request, f1.getId());
                            for(int j = 0; j < f2List.size(); j++){
                                SysFunction f2 = f2List.get(j);
                                String menuSelected = "";
                                boolean isActiveF2 = WebUtils.isFuncActive_Cache(request,f2, fIdLeftPage);
                                if(isActiveF2){
                                    menuSelected = "active selected";
                                    GLOBAL_MENU_NAME = f2.getFuncName();
                                }
                %>
                <li class="<%=menuSelected%>"><a href="${ctx}<%=WebUtils.addQueryParam(f2.getActionUrl(), FUNC_KEY_LEFTPAGE, f2.getId().toString())%>"><%=f2.getFuncName()%></a></li>
                <%
                            }
                %>
                <%
                        }
                %>
                <%
                    }
                %>
            </ul>
        </li>
        <%
            }
        %>
    </ul>
</div><!-- /.sidebar-left -->
<!-- END SIDEBAR LEFT -->